package com.xasz.controller;

import com.xasz.entity.Candidate;

import com.xasz.service.ICandidateService;
import com.xasz.service.IJuryService;
import com.xasz.service.impl.CandidateServiceImpl;
import com.xasz.util.JsonResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cai
 * @since 2022-07-28
 */
@AllArgsConstructor
@RestController
@RequestMapping("candidate")
public class CandidateController extends BaseController{
    private CandidateServiceImpl candidateService;

    /**
     * 增加候选人
     */
    @PostMapping
    public JsonResult<Void> inputCandidate(@RequestBody Candidate candidate, HttpSession session) {
        candidateService.addCandidate(candidate,getUidFromSession(session));

        return new JsonResult<>(OK);
    }

    /**
     * 删除候选人
     */
    @DeleteMapping
    public JsonResult<Void> DeleteCandidate(@RequestBody Candidate candidate, HttpSession session) {
        candidateService.deleteCandidate(candidate,getUidFromSession(session));
        return new JsonResult<>(OK);
    }

    /**
     * 修改候选人
     */
    @PutMapping
    public JsonResult<Void> updateCandidate(@RequestBody Candidate candidate, HttpSession session){
        candidateService.upDataCandidate(candidate,getUidFromSession(session));
        return new JsonResult<>(OK);
    }

    /**
     * 通过活动id查询有哪些候选人
     */
    @GetMapping
    public JsonResult<List<Candidate>> getCandidate(Integer Aid,HttpSession session){
        return new JsonResult<>(OK,candidateService.getCandidate(Aid,getUidFromSession(session),getUsernameFromSession(session)));
    }

}